package org.geektime.task.sbcachemanager.service.impl;

import org.geektime.task.sbcachemanager.bean.User;
import org.geektime.task.sbcachemanager.service.ICacheManagerService;
import org.springframework.cache.annotation.CacheEvict;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.stereotype.Service;

@Service
public class CacheManagerService implements ICacheManagerService {


    /**
     * 查询并设置缓存
     * @param userId
     * @return
     */
    @Override
    @Cacheable(cacheNames="users", key="#userId")
    public User getUserById(String userId){
        System.out.println("***********请求进入业务层进行查询*********");

        User user = new User("001","我是人","我在北京");

        return user;
    }


    /**
     * 删除缓存
     */
    @CacheEvict(cacheNames="users",key="#userId")
    @Override
    public void deleteUser(String userId){
        System.out.println("***********请求进入业务层进行删除用户*********");

    }


}
